package map;

import com.sun.javafx.collections.MappingChange;

import java.util.*;

/**
 * @Author Klys
 * @Date 2023/6/4 15:21
 * @Description
 * @Version 1.0
 */
public class Demo01 {

    public static void main(String[] args) {

        HashMap<Object, Object> objectHashMap = new HashMap<>();
        objectHashMap.put(1, "klys");
        objectHashMap.put(2, "klys");
        objectHashMap.put(null, null);
        System.out.println(objectHashMap);

        Set<Object> keySet = objectHashMap.keySet();
        System.out.println(keySet);

        Set<Map.Entry<Object, Object>> entries = objectHashMap.entrySet();
        System.out.println(entries);

        for (Object key : objectHashMap.keySet()
        ) {
            System.out.println(key);
            System.out.println(objectHashMap.get(key));
        }

        Iterator<Map.Entry<Object, Object>> entryIterator = objectHashMap.entrySet().iterator();
        while (entryIterator.hasNext()) {
            System.out.println(entryIterator.next());
        }


        Set<Object> hashSet = new HashSet<>();
        hashSet.add(1);
        hashSet.add(1);
        System.out.println(hashSet);
        Iterator<Object> iterator = hashSet.iterator();
        System.out.println(iterator.next());

        hashSet.forEach((value) -> {
            if (value.equals(1)) {
                value = "klys";
                System.out.println(value + "已修改");
            }
        });
        System.out.println(hashSet);

        HashMap<String, String> map = new HashMap<>();
        map.put("1", "liu");
        map.put("2", "klys");
        map.forEach((key, value) -> {
            if (key.equals("1")) {
                key = "klys";
            }
        });
        System.out.println(map);

    }
}
